Skip to content

Conversation

Kumataro
Copy link
Contributor

fix #4009

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

int size = _width * _height;
memcpy(&bytes[0], &source[0], size);

if( bytes != nullptr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes just initialized at line 33 with nullptr. Most probably it's a typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review !

bytes just initialized at line 33 with nullptr. Most probably it's a typo.

bytes are allocated in init() function.

ByteMatrix::ByteMatrix(int _width, int _height, ArrayRef<char> source) : bytes(nullptr) {
    init(_width, _height);

    if( bytes != nullptr)
    {
        const size_t size = _width * _height;
        memcpy(&bytes[0], &source[0], size);
    }
}

But If one of _height and/or _width is less than 1 at (1) , bytes will not be allocated and keeps nullptr at (2).

void ByteMatrix::init(int _width, int _height) {
    if (_width < 1 || _height < 1) {  // (1)
        return;
    }
    this->width = _width;
    this->height = _height;
    bytes = new unsigned char[width * height]; // (2)
    row_offsets = new int[height];
    row_offsets[0] = 0;
    for (int i = 1; i < height; i++) {
        row_offsets[i] = row_offsets[i - 1] + width;
    }
}

@asmorkalov asmorkalov merged commit 04c05a1 into opencv:4.x Oct 1, 2025
13 checks passed
@asmorkalov asmorkalov mentioned this pull request Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GCC 15 warns -Wmaybe-uninitialized on text and wechat_qrcode module
2 participants